package com.wlyuan.open.scanner.utils.enums.quotation;

import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValueMap;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
 * @author lijing
 * @description 合约报价类型
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum TemplateCreateTypeEnum implements NamedValue<Integer> {

    ONLINE_CUSTOMER(1, 1, "线上客户"),
    OFFLINE_CUSTOMER(2, 0, "线下客户"),
    OFFLINE_SUPPLIER(3, 0, "线下承运商"),
    MYSELF(4, 2, "自营司机"),
    PERSONAL(5, 3, "个体司机");

    private final Integer value;
    private final Integer newValue;
    private final String name;


    private static final Map<Integer, TemplateCreateTypeEnum> MAP = new NamedValueMap<>(TemplateCreateTypeEnum.class);

    public static TemplateCreateTypeEnum fromValue(Integer value) {
        return MAP.get(value);
    }


    private static final Set<Integer> CUSTOMER = new HashSet<>();
    private static final Set<Integer> CARRIER = new HashSet<>();

    static {
        CUSTOMER.add(ONLINE_CUSTOMER.value);
        CUSTOMER.add(OFFLINE_CUSTOMER.value);
        CARRIER.add(OFFLINE_SUPPLIER.value);
        CARRIER.add(MYSELF.value);
        CARRIER.add(PERSONAL.value);
    }

    public static boolean customer(Integer value) {
        return Optional.ofNullable(value).map(v -> CUSTOMER.contains(v)).orElse(false);
    }

    public static boolean carrier(Integer value) {
        return Optional.ofNullable(value).map(v -> CARRIER.contains(v)).orElse(false);
    }
}
